//
//  LCPickerView.m
//  JavaMall
//
//  Created by 东亨 on 2017/6/26.
//  Copyright © 2017年 Enation. All rights reserved.
//

#import "LCPickerView.h"

@interface LCPickerView ()<UIPickerViewDelegate,UIPickerViewDataSource>
{
    NSInteger  _pickSelect;
}
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
@property (strong,nonatomic)NSArray  *titleArr;

@end

@implementation LCPickerView
+(LCPickerView *)initCustomView
{
    NSArray *array = [[NSBundle mainBundle]loadNibNamed:@"LCPickerView" owner:nil options:nil];
    return [array objectAtIndex:0];
}
- (void)awakeFromNib
{
    [super awakeFromNib];
    _titleArr = @[@"官网推荐",@"用户推荐"];
    _pickerView.delegate = self;
    _pickerView.dataSource = self;
}
#pragma mark -UIPickerViewDelegate
#pragma mark-pickerView
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return _titleArr.count;
}
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)componen
{
    return _titleArr[row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    _pickSelect = row;
}
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

    UILabel *pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        // Setup label properties - frame, font, colors etc
        //adjustsFontSizeToFitWidth property to YES
        pickerLabel.minimumScaleFactor = 0.2;
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont boldSystemFontOfSize:15]];
    }
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    return pickerLabel;
}

- (IBAction)sureBtnClick:(UIButton *)sender
{
    if (self.refereesBlock)
    {
        self.refereesBlock(_titleArr[_pickSelect]);
    }
    [UIView animateWithDuration:0.3 animations:^{
        self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 180);
    }];
}
//取消
- (IBAction)disBtnClick:(UIButton *)sender
{
    [UIView animateWithDuration:0.3 animations:^{
          self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 180);
    }];
}

@end
